<template>
  <div class="gmU">
    <headerNav />
    <div class="mindWidth">
      <div class="mincard">
        <span @click="$router.push('/')">首页</span>>
        <span>政策解读</span>
      </div>
      <div class="filterKeyWord mindWidth">
        <div class="region_H">
          <div class="area_name">
            <div class="area_content" v-for="(item, index) in selectRegion" :key="index">
              <div class="area_content_L">
                <span v-if="index == 0">地区:</span>
              </div>
              <span class="all active changeHanld">
                {{ item }}
                <img
                  src="../../../static/image/region_cha.png"
                  v-show="isShowError"
                  @click="cancelSelect(index)"
                />
              </span>
            </div>

            <div class="area_content" :class="!showMore ? 'active' : ''">
              <div class="area_content_L">
                <span v-if="selectRegion.length == 0">地区:</span>
              </div>
              <span
                v-if="selectRegion.length < 2"
                class="all changeHanld"
                :class="!selectIndex ? 'active' : ''"
              >全部</span>

              <div class="areaItem" v-if="selectRegion.length == 0">
                <div
                  class="area_content_R changeHanld"
                  :class="selectIndex ? 'active' : ''"
                  v-for="(item, index) in currentProvinceList"
                  :key="index"
                  @click="selectItem(index, item.province || item.name || item,'province')"
                >
                  <span class="changeHanld" v-if="item.province">
                    {{
                    item.province
                    }}
                  </span>
                </div>
              </div>

              <div class="areaItem" v-if="selectRegion.length == 1">
                <div
                  class="area_content_R changeHanld"
                  :class="selectIndex ? 'active' : ''"
                  v-for="(item, index) in currentProvinceList"
                  :key="index"
                  @click="selectItem(index, item.province || item.name || item,'city')"
                >
                  <!-- item.province || item.name || item1  -->
                  <span class="changeHanld">
                    {{
                    item.province || item.name
                    }}
                  </span>
                </div>
              </div>

              <div class="areaItem" v-if="selectRegion.length == 2">
                <div
                  class="area_content_R changeHanld"
                  :class="celctselect == index ? 'active' : ''"
                  v-for="(item, index) in currentProvinceList"
                  :key="index"
                  @click="selectItem(index, item.province || item.name || item,'area')"
                >
                  <!-- item.province || item.name || item2  -->
                  <span class="changeHanld">
                    {{
                    item.province || item.name || item
                    }}
                  </span>
                </div>
              </div>
              <div
                v-if="
                  selectRegion.length == 0 && judgeWords(currentProvinceList, 1)
                "
              >
                <div class="more changeHanld" @click="showMore = !showMore" v-show="showMore">
                  更多
                  <i
                    :class="
                      showMore ? 'el-icon-caret-bottom' : 'el-icon-caret-top'
                    "
                  ></i>
                </div>
                <div class="more changeHanld" @click="showMore = !showMore" v-show="!showMore">
                  收起
                  <i
                    :class="
                      !showMore ? 'el-icon-caret-top' : 'el-icon-caret-bottom'
                    "
                  ></i>
                </div>
              </div>
              <div
                v-if="
                  selectRegion.length == 1 && judgeWords(currentProvinceList, 2)
                "
              >
                <div class="more changeHanld" @click="showMore = !showMore" v-show="showMore">
                  更多
                  <i
                    :class="
                      showMore ? 'el-icon-caret-bottom' : 'el-icon-caret-top'
                    "
                  ></i>
                </div>
                <div class="more changeHanld" @click="showMore = !showMore" v-show="!showMore">
                  收起
                  <i
                    :class="
                      !showMore ? 'el-icon-caret-top' : 'el-icon-caret-bottom'
                    "
                  ></i>
                </div>
              </div>
              <div
                v-if="
                  selectRegion.length == 2 && judgeWords(currentProvinceList, 3)
                "
              >
                <div class="more changeHanld" @click="showMore = !showMore" v-show="showMore">
                  更多
                  <i
                    :class="
                      showMore ? 'el-icon-caret-bottom' : 'el-icon-caret-top'
                    "
                  ></i>
                </div>
                <div class="more changeHanld" @click="showMore = !showMore" v-show="!showMore">
                  收起
                  <i
                    :class="
                      !showMore ? 'el-icon-caret-top' : 'el-icon-caret-bottom'
                    "
                  ></i>
                </div>
              </div>
            </div>
          </div>
          <div class="section_item">
            <div class="section_title">受理部门:</div>
            <span
              class="section_all"
              :class="DepartmentAll == -1 ? 'active' : ''"
              @click="selectSection(-1)"
            >全部</span>
            <div
              v-if="receiverDepartment.length > 0"
              class="section_centent_item"
              :class="controlHeight ? 'item_minHeight' : ''"
            >
              <div
                class="item changeHanld"
                v-for="(item, index) in receiverDepartment"
                :key="index"
                @click="selectSection(index, item.id)"
                :class="DepartmentAll === index ? 'active' : ''"
              >{{ item == null ? "没有数据" : "" || item.departmentName }}</div>
            </div>
            <div v-if="judgeWords(receiverDepartment, 4)">
              <div
                class="more changeHanld"
                @click="controlHeight = !controlHeight"
                v-show="controlHeight"
              >
                收起
                <i
                  :class="
                    controlHeight ? 'el-icon-caret-top' : 'el-icon-caret-bottom'
                  "
                ></i>
              </div>
              <div
                class="more changeHanld"
                @click="controlHeight = !controlHeight"
                v-show="!controlHeight"
              >
                更多
                <i
                  :class="
                    !controlHeight
                      ? 'el-icon-caret-bottom'
                      : 'el-icon-caret-top'
                  "
                ></i>
              </div>
            </div>
          </div>
          <!-- 截止时间 -->
          <div class="section_item">
            <div class="section_title">截止时间:</div>
            <span
              class="section_all"
              :class="stopTimeAll === -1 ? 'active' : ''"
              @click="cancelSelectAll(-1)"
            >全部</span>
            <div class="section_centent_item">
              <div
                class="item changeHanld"
                @click="getstopTime(v, i)"
                v-for="(v, i) in stopTime"
                :key="i"
                :class="stopTimeAll === i ? 'active' : ''"
              >{{ v }}天内截止</div>
            </div>
          </div>
        </div>
        <div class="detail">
          <div class="detailText">
            <span>关键词:</span>
            <div class="wirteSize">
              <input type="text" placeholder="请输入关键词" v-model="title" />
              <button class="dominant changeHanld" @click="handleSearch">搜索</button>
            </div>
          </div>
          <div class="detailAtlas dominant changeHanld" @click="$router.push('/policyMap')">政策图谱</div>
        </div>
      </div>
    </div>
    <div class="mindWidth wrapper">
      <div class="project_title_bg">
        <span class="name">项目名称</span>
        <span class="department">受理部门</span>
        <span class="region">地区</span>
        <span class="date">申报时间</span>
        <span class="condition">申报条件</span>
      </div>
    </div>
    <div
      class="mindWidth project_title_content_bg"
      style="min-height: 490px"
      v-loading="loading"
      v-show="notYet"
    >
      <div
        class="project_title_content_list changeHanld"
        @click="handleClick(item.id)"
        v-for="(item, index) in provinceListItem"
        :key="index"
      >
        <span
          class="name singlerows hovuers"
          v-html="searchHighlight(item.title)"
          :title="item.title"
        ></span>
        <span
          class="department singlerows hovuers"
          :title="item.departmentName"
          @click="goDepartmentPage(item.departmentId)"
        >{{ item.departmentName }}</span>
        <span class="region singlerows">{{ item.address }}</span>
        <span
          class="date singlerows"
          v-if="item.declareTime != null || item.deadline != null"
        >{{ item.declareTime + " - " + item.deadline }}</span>
        <span class="date singlerows" v-else>-</span>

        <span class="condition singlerows">{{ item.declareCondition }}</span>
      </div>
    </div>
    <div
      class="mindWidth project_title_content_bg content_imgse"
      style="min-height: 490px; background-color: transparent"
      v-show="!notYet"
    >
      <img src="../../../static/image/noDataBox.png" alt />
      <p>暂无数据</p>
    </div>
    <div class="mindWidth pageList">
      <div class="page">
        <paging ref="paging_zi" v-on:CurrentPage="accept_CurrentValue" :pageNo="pageNos" />
      </div>
    </div>
    <footer-nav />
    <Navigation />
  </div>
</template>

<script>
import { commonRequest, postRequest } from "../../api/api.js";
import paging from "../../components/paging.vue"; //分页
import { sessionTake } from "../../util/validate";

export default {
  name: "governemntUnscramble",
  components: {
    paging
  },
  head() {
    return {
      title: "政策解读-比目镜",
      meta: [
        {
          hid: "description",
          name: "description",
          content:
            "比目镜(51bmj.cn)，科技产业政策项目数据平台，提供行业扶持资助补贴政策查询、政府部门最新政策实时智能推送、高新技术企业公示名单查询、高新技术企业项目立项查询、高新技术企业荣誉资质查询、高新技术企业商标专利查询、高新技术企业名单统计、科技项目申报查询、政策项目智能匹配、园区孵化器企业查询、政策扶持项目申报服务"
        },
        {
          hid: "keywords",
          name: "keywords",
          content:
            "比目镜，政策查询，政策智能推送，最新政策，政策解读，政策匹配，政府黄页，企业名单，企业查询，企业项目立项查询，高新技术企业名单查询，高企名单，专利查询，商标查询，专利交易信息发布，高新技术企业认定，科技项目申报"
        }
      ]
    };
  },
  data() {
    return {
      // 默认高度
      item_height: false,
      // 地区列表
      provinceList: [],
      // 显示全部省份
      allProvince: -1,

      // 选择地区
      selectRegion: [],
      // 选择的省份
      selectProvinceName: -1,
      // 选中的城市
      selectCityName: -1,
      // 选中的地区
      selecteactName: -1,
      // 受理部门
      receiverDepartment: [],
      DepartmentAll: -1, // 受理部门的全部
      stopTimeAll: -1, // 截止时间
      stopTime: ["7", "30"],
      provinceListItem: [], // 文章列表详情
      controlHeight: false, // 控制高度
      searchItem: {
        address: "", // 选中地址
        closeDay: "", // 截止天数
        departmentId: "" // 部门id
      },
      title: "", // 关键字
      keywordValue: "",
      selectIndex: false, // 选择地区项
      celctselect: -1,
      showMore: true, // 显示地区的更多
      pageNos: 1,
      loading: true,
      notYet: true
    };
  },
  computed: {
    isShowError() {
      let params = this.$store.state.cityInfo;
      if (params.city === "" && params.province === "") {
        return true;
      } else {
        return false;
      }
    },
    currentProvinceList() {
      if (this.selectRegion.length > 0) {
        // 选中第一级  省
        let item = this.provinceList.filter(el => {
          // console.log(el);
          // 找出对应的项
          if (el.province != "") {
            if (el.province == this.selectRegion[0])
              if (el.province == this.selectRegion[0]) {
                return el;
              }
          }
        });
        let arr = item[0] && item[0].city;
        // 如果有city属性的话才会显示第二项的数据;
        if (this.selectRegion.length > 1) {
          // 选中第二级  市
          let item = arr.filter(v => {
            if (v.name == this.selectRegion[1]) {
              return v;
            }
          });
          if (this.selectRegion.length == 2) {
            // 选中第三级  区
            return item[0] && item[0].area;
          }
        } else {
          return arr;
        }
        return arr;
      } else {
        // // 一开始显示全部
        return this.provinceList;
      }
    }
  },
  watch: {
    searchItem: {
      deep: true,
      handler(val) {
        console.log("684", val);
        // this.accept_CurrentValue(1);
        this.pageNos = 1;
        // console.log(val);
        this.getprovinceList();
        // 获取部门
        this.acceptSection();
      }
    }
  },
  mounted() {
    // 获取地区
    this.getRegion();
  },
  methods: {
    // 获取地区列表
    getRegion() {
      commonRequest("/api/pms/pmsDepartment/getAllDepartmentArea?type=1").then(
        res => {
          if (sessionTake("provinceName") !== null) {
            for (let i = 0; i < res.length; i++) {
              if (res[i].province == sessionTake("provinceName")) {
                for (let j = 0; j < res[i].city.length; j++) {
                  if (res[i].city[j].name == sessionTake("cityName")) {
                    this.selectRegion = [res[i].province, res[i].city[j].name];
                    this.searchItem.province = res[i].province;
                    this.searchItem.address = res[i].city[j].name;
                    this.searchItem.city = res[i].city[j].name;
                  }
                }
              }
            }
          }
          this.provinceList = res;
        }
      );
    },
    // 获取列表数据
    getprovinceList(pageNo) {
      if (pageNo) {
        this.pageNos = pageNo;
      } else {
        this.pageNos = 1;
      }

      this.notYet = true;
      this.provinceListItem = "";
      let obj = {
        title: this.title, // 关键字
        address: this.searchItem.address, // 选中地址
        province: this.searchItem.province, // 选中省份
        city: this.searchItem.city, // 选中城市
        area: this.searchItem.area, // 选中区域
        closeDay: this.searchItem.closeDay, // 截止天数
        departmentId: this.searchItem.departmentId, // 受理部门
        pageNo: this.pageNos
      };
      if (this.title != "") {
        this.keywordValue = this.title;
      }
      for (const key in obj) {
        if (!String(obj[key]).length) delete obj[key];
      }
      /* 添加loading */
      this.loading = true;
      commonRequest("/api/pms/pmsPolicyInterpret/list", obj).then(res => {
        // console.log(res);
        this.provinceListItem = res.records;
        this.$refs.paging_zi.totalValue(res.total);
        this.loading = false;
        if (res.records.length == 0) {
          this.notYet = false;
        }
      });
    },
    // 受理部门接口
    acceptSection() {
      var shen = "";
      var shi = "";
      var qu = "";
      if (this.selectRegion.length == 1 && this.celctselect == -1) {
        shen = this.selectRegion[0];
      }
      if (this.selectRegion.length == 2 && this.celctselect == -1) {
        shi = this.selectRegion[1];
      }

      if (this.celctselect != -1) {
        qu = this.currentProvinceList[this.celctselect];
      }
      commonRequest(
        "/api/pms/pmsPolicyInterpret/queryPolicyInterpretAcceptDepartment",
        {
          province: shen,
          city: shi,
          area: qu
        }
      ).then(res => {
        // console.log(1,res);
        this.receiverDepartment = res;
      });
    },
    // 获取截止天数
    getstopTime(val, index) {
      this.searchItem.closeDay = val;
      this.stopTimeAll = index;
    },
    // 点击搜索按钮
    handleSearch() {
      this.getprovinceList();
      // 获取部门
      this.acceptSection();
    },
    // 点击获取数据列表
    handleClick(id) {
      // window.open("/gUDetails?id=" + id, "_blank");
      window.open(`/gUDetails/${id}`);
    },
    goDepartmentPage(departmentId) {
      window.open("/departmentInside?id=" + departmentId, "_blank");
    },
    judgeWords(data, index) {
      // console.log(index);
      if (data == undefined || data == "") {
        return false;
      }
      // 1省级2市级3区级
      if (index == 1) {
        // console.log("382", data);
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            if (data[i].province != "") {
              str = str + data[i].province;
            }
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            // return null;
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      if (index == 2) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i].name;
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      if (index == 3) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i];
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      if (index == 4) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i].departmentName;
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
    },
    // 搜索高亮
    searchHighlight(val) {
      var that = this;
      if (that.keywordValue == "") {
        return val;
      } else {
        return val.replace(
          new RegExp(that.keywordValue, "g"),
          "<em style='color: red;font-style:normal;'>" +
            that.keywordValue +
            "</em>"
        );
      }
    },
    // 选中
    selectItem(index, val, property) {
      console.log(index, val, property);
      this.DepartmentAll = -1;
      this.searchItem.departmentId = "";
      // 添加到数组
      if (this.selectRegion.length < 2) {
        this.selectRegion.push(val);
      } else {
        this.celctselect = index;
      }
      // 赋值
      this.searchItem.address = val;
      this.searchItem[property] = val;
    },
    // 移除
    cancelSelect(index) {
      if (index === 0) {
        this.searchItem.address = "";
        this.searchItem.province = "";
        this.searchItem.city = "";
        this.searchItem.area = "";
      } else {
        this.searchItem.address = "";
        this.searchItem.city = "";
        this.searchItem.area = "";
      }
      this.celctselect = -1;
      this.DepartmentAll = -1;
      this.searchItem.departmentId = "";
      // 通过索引移除当前索引及后面的所有元素
      this.selectRegion.splice(index);
      // 赋值
      this.searchItem.address = this.selectRegion[this.selectRegion.length - 1];
      this.acceptSection();
    },
    // 取消选中全部按钮
    cancelSelectAll(val) {
      this.stopTimeAll = val;
      this.searchItem.closeDay = "";
    },

    // 点击受理部门
    selectSection(index, item) {
      if (index < 0) {
        // 全部
        this.DepartmentAll = -1;
        this.searchItem.departmentId = "";
        return;
      }
      this.searchItem.departmentId = item;
      // console.log(item);
      this.DepartmentAll = index;
    },

    // 接受当前选中页数
    accept_CurrentValue(value) {
      this.getprovinceList(value);
    }
  }
};
</script>

<style lang="less" scoped>
.hovuers:hover {
  color: rgb(68, 162, 255);
}

.content_imgse {
  background-color: transparent !important;
  box-shadow: 0 0 black !important;
  overflow: hidden;
  text-align: center;

  img {
    margin: 0 auto;
    margin-top: 138px;
    width: 280px;
  }

  p {
    color: rgb(204, 204, 204);
    font-size: 14px;
    margin-top: 10px;
  }
}

.gmU {
  //
  .mincard {
    span {
      font-size: 14px;
      margin: 0 10px;
      cursor: pointer;
    }
  }

  .filterKeyWord {
    padding: 10px 0;
    background-color: #fff;

    .region_H {
      .area_name {
        border-bottom: 1px solid rgb(238, 238, 238);
      }

      .area_content {
        position: relative;
        display: flex;
        align-content: center;
        max-height: 50px;
        overflow: hidden;
        padding: 5px 0;
        // flex-wrap: wrap;
        // align-items: center;
        &.active {
          max-height: 1000px;
          align-items: flex-start;
        }

        .allProvince_item {
          display: flex;
          flex: 1;
          max-height: 100px;
        }

        .more {
          position: absolute;
          top: 12px;
          right: 21px;
          color: #44a2ff;
          font-size: 14px;

          &.active {
            color: #44a2ff;
          }
        }

        .all {
          position: relative;
          display: flex;
          align-items: center;
          justify-content: center;
          height: 30px;
          padding: 0px 10px;
          border-radius: 4px;
          font-size: 14px;
          margin-left: 2px;

          &.active {
            background-color: #44a2ff;
            color: #fff;

            img {
              width: 16px;
              position: absolute;
              top: -2px;
              right: -2px;
            }
          }
        }

        .area_content_L {
          width: 135px;
          padding-top: 3px;
          padding-left: 20px;

          span {
            font-size: 14px;
          }
        }

        .areaItem {
          display: flex;
          flex-wrap: wrap;
          width: 930px;
        }

        .area_content_R {
          display: flex;
          border-radius: 6px;
          height: 35px;

          span {
            font-size: 14px;
            display: flex;
            margin: 0 8px;
            align-items: center;
            border-radius: 4px;
            padding: 0px 10px;
            color: rgb(51, 51, 51);

            &:hover {
              background-color: #44a2ff;
              border-radius: 4px;
              color: #fff;
            }
          }

          &.active {
            background-color: #44a2ff;
            color: #fff;

            span {
              color: #fff;
            }
          }
        }
      }

      .section_item {
        display: flex;
        padding: 15px 0;
        border-bottom: rgb(238, 238, 238) 1px solid;

        .section_title {
          margin-left: 20px;
          width: 96px;
          font-size: 14px;
        }

        .section_all {
          width: 50px;
          height: 30px;
          text-align: center;
          margin: 0 20px;
          line-height: 30px;
          font-size: 14px;

          &.active {
            border-radius: 4px;
            background-color: #44a2ff;
            color: #fff;
          }
        }

        .section_centent_item {
          display: flex;
          overflow: hidden;
          max-height: 30px;
          flex-wrap: wrap;
          flex: 1;

          &.item_minHeight {
            min-height: 30px;
            max-height: 7000px;
          }

          .item {
            font-size: 14px;
            margin-left: 10px;
            padding: 6px 8px;
            color: rgb(51, 51, 51);
            border-radius: 4px;
            height: 30px;

            &:hover {
              background-color: #44a2ff;
              border-radius: 4px;
              color: #fff;
            }

            &.active {
              border-radius: 6px;
              background-color: #44a2ff;
              color: #fff;
            }
          }
        }

        .more {
          font-size: 14px;
          color: #44a2ff;
          margin-right: 20px;
        }
      }
    }
  }

  .detail {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .detailText {
      display: flex;
      align-items: center;

      span {
        width: 116px;
        padding-left: 20px;
        font-size: 14px;
        margin-right: 20px;
      }

      .wirteSize {
        display: flex;
        height: 32px;
        width: 300px;
        font-size: 0;

        input {
          border-radius: 4px 0 0 4px;
          width: 240px;
          border: 1px solid #44a2ff;
          height: 100%;
          display: block;
          padding-left: 10px;
          font-size: 14px;
        }

        button {
          border-radius: 0px 4px 4px 0px;
          float: left;
          width: 60px;
          height: 100%;
          padding: 0;
          margin-left: -1px;
        }
      }
    }

    .detailAtlas {
      width: 80px;
      height: 32px;
      line-height: 30px;
      background: rgb(68, 162, 255);
      border-radius: 4px;
      text-align: center;
      color: rgb(255, 255, 255);
      cursor: pointer;
      margin-right: 20px;
    }
  }

  .project_title_bg {
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 10px;

    span {
      margin: 0 10px;
      color: #fff;
      font-size: 14px;
    }

    .name {
      flex: 3;
    }

    .department {
      flex: 1;
    }

    .region {
      flex: 1;
    }

    .date {
      flex: 2;
    }

    .condition {
      flex: 2;
    }
  }

  .project_title_content_bg {
    background-color: #fff;
    margin: 20px auto;
  }

  .project_title_content_list {
    margin: 10px auto;
    height: 40px;
    display: flex;
    align-items: center;

    span {
      margin: 0 10px;
      font-size: 14px;
    }

    .name {
      flex: 3;
    }

    .department {
      flex: 1;
    }

    .region {
      flex: 1;
    }

    .date {
      flex: 2;
    }

    .condition {
      flex: 2;
    }
  }

  .pageList {
    height: 100px;
    display: flex;
    flex-direction: row-reverse;
  }

  .page {
    display: flex;
    float: right;
    align-items: center;

    .pageNum {
      font-size: 14px;
      margin-right: 20px;

      span {
        color: #44a2ff;
        margin: 0 5px;
      }
    }

    .tempPage {
      margin-left: 10px;

      input {
        margin: 0 5px;
        text-align: center;
        width: 30px;
        height: 30px;
        border: 1px solid #ccc;
      }
    }
  }
}
</style>
